package com.iking.housekeeping.service.elderlyrelation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.iking.housekeeping.common.PageParam;
import com.iking.housekeeping.dao.elderlyrelation.ElderlyRelationMapper;
import com.iking.housekeeping.entity.elderlyrelation.ElderlyRelation;

/**
 * 家属
 * 
 * @author: gf
 * @date: 2018年4月23日 上午11:34:56
 */
@Service
public class ElderlyRelationService {

	/**
	 * 家属操作
	 */
	@Autowired
	private ElderlyRelationMapper elderlyRelationMapper;	
	
	/**
	 * 	添加家属信息
	 *  @param req
	 *  @return int
	 *  @author gf
	 */
	public int insert(ElderlyRelation req) {
		return elderlyRelationMapper.insertSelective(req);
	}
	
	/**
	 * 	删除家属
	 *  @param fId
	 *  @return int
	 *  @author gf
	 */
	public int delete(String fId) {
		return elderlyRelationMapper.deleteByFid(fId);
	}
	
	/**
	 * 	更新家属
	 *  @param req
	 *  @return int
	 *  @author gf
	 */
	public int update(ElderlyRelation req) {
		return elderlyRelationMapper.updateByPrimaryKeySelective(req);
	}
	
	/**
	 * 	分页查询家属信息
	 *  @param pageParam
	 *  @return Page<ElderlyRelation>
	 *  @author gf
	 */
	public Page<ElderlyRelation> selectByPage(PageParam pageParam){
		//设置分页大小和当前页
		PageHelper.startPage(pageParam.getPageCurrent(), pageParam.getPageSize());
		//执行查询
		return elderlyRelationMapper.selectByPage();
	}
	
	/**
	 * 	通过老人id查询家属
	 *  @param fId
	 *  @return List<ElderlyRelation>
	 *  @author gf
	 */
	public List<ElderlyRelation> selectByEldId(String fId){
		return elderlyRelationMapper.selectByEldId(fId);
	}
	
	/**
	 * 	更新家属的老人id
	 *  @param fElderly
	 *  @return int
	 *  @author gf
	 */
	public int updateElderly(String fElderly) {
		return elderlyRelationMapper.updateElderly(fElderly);
	}
	
	/**
	 * 	通过老人id删除家属
	 *  @param fElderlyId
	 *  @return int
	 *  @author gf
	 */
	public int deleteByElderly(String fElderlyId) {
		return elderlyRelationMapper.deleteByElderly(fElderlyId);
	}
}
